<!-- 确认取货 -->
<template>
	<ListLayout>
		<AttachmentCard ref="AttachmentCard"></AttachmentCard>
		<SignCard ref="SignCard"></SignCard>
		<template #footer>
			<HButtonGroup @leftClick="onCancel" @rightClick="onConfirmPickup">
				<template #left>
					取消
				</template>
				<template #right>
					确认设备取走
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>

</template>

<script>
	import ListLayout from '@/components/layout/listLayout.vue'
	import QuoteCard from '@/components/card/sendRepair/factory/quote.vue'
	import AttachmentCard from '@/components/card/attachment.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import SignCard from '@/components/card/sign.vue'
	import ReapirApi from '@/apis/repair.js'
	import { attachmentFormatter } from '@/common/submitFormatter.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	export default {
		components: {
			ListLayout,
			QuoteCard,
			AttachmentCard,
			SignCard,
			HButtonGroup,

		},
		data() {
			return {
				routerParams: {
					id: ''
				}
			}

		},
		onLoad(query) {
			const {
				id
			} = query
			this.$set(this.routerParams, 'id', id)
		},
		methods: {
			onCancel() {
				wx.navigateBack()
			},
			onConfirmPickup() {
				let {
					AttachmentCard,
					SignCard
				} = this.$refs;
				let {
					attachment
				} = AttachmentCard.$data
				SignCard.upSign(async (file) => {
					let params = {
						repairId: this.routerParams.id,
						sign: file?.url || '',
						autograph: '',
						remark: '',
						enclosure: attachmentFormatter(attachment)
					}

					await ReapirApi.factory.devicePickUp(params)
					wx.showToast({
						title: '取走成功!',
						icon: 'success',
						complete() {
							wx.redirectTo({
								url: SendRepairRouterConfig.Factory.Index
							})
						}
					})


				})

			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
